package com.jcfy.project.module.client;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jcfy.common.utils.poi.ExcelUtil;
import com.jcfy.framework.aspectj.lang.annotation.Log;
import com.jcfy.framework.aspectj.lang.enums.BusinessType;
import com.jcfy.framework.web.controller.BaseController;
import com.jcfy.framework.web.domain.AjaxResult;
import com.jcfy.project.module.domain.TTeam;
import com.jcfy.project.module.service.ITTeamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 团长(自提点)Controller
 *
 * @author hushuai
 * @date 2020-08-16
 */
@RestController
@RequestMapping("/client/team" )
public class TeamController extends BaseController {
    @Autowired
    private ITTeamService tTeamService;

    /**
     * 查询团长(自提点)列表
     */
    @PostMapping("/list" )
    public AjaxResult list(TTeam tTeam, Integer pageNum, Integer pageSize) {
        System.out.println(tTeam);
        tTeam.setStatus(0);
        PageHelper.startPage(pageNum, pageSize).setOrderBy("distance ASC");
        List<TTeam> list = tTeamService.selectTTeamList(tTeam);
        PageInfo<TTeam> pageInfo = new PageInfo<TTeam>(list);
        return AjaxResult.success(pageInfo);
    }




    /**
     * 导出团长(自提点)列表
     */
    @PreAuthorize("@ss.hasPermi('module:team:export')" )
    @Log(title = "团长(自提点)" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(TTeam tTeam) {
        List<TTeam> list = tTeamService.selectTTeamList(tTeam);
        ExcelUtil<TTeam> util = new ExcelUtil<TTeam>(TTeam. class);
        return util.exportExcel(list, "team" );
    }

    /**
     * 获取团长(自提点)详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:team:query')" )
    @GetMapping(value = "/{teamId}" )
    public AjaxResult getInfo(@PathVariable("teamId" ) Long teamId) {
        return AjaxResult.success(tTeamService.selectTTeamById(teamId));
    }

    /**
     * 新增团长(自提点)
     */
    @PreAuthorize("@ss.hasPermi('module:team:add')" )
    @Log(title = "团长(自提点)" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TTeam tTeam) {
        return toAjax(tTeamService.insertTTeam(tTeam));
    }

    /**
     * 修改团长(自提点)
     */
    @PreAuthorize("@ss.hasPermi('module:team:edit')" )
    @Log(title = "团长(自提点)" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TTeam tTeam) {
        return toAjax(tTeamService.updateTTeam(tTeam));
    }

    /**
     * 删除团长(自提点)
     */
    @PreAuthorize("@ss.hasPermi('module:team:remove')" )
    @Log(title = "团长(自提点)" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{teamIds}" )
    public AjaxResult remove(@PathVariable Long[] teamIds) {
        return toAjax(tTeamService.deleteTTeamByIds(teamIds));
    }
}
